package com.bright.hxj.qchz.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author hxj
 * @Date 2025/1/4 16:44
 * @Description
 */
@Configuration
public class ExecutorServiceConfig {
    @Value("${duijie.maxThreadSize:30}")
    private int maxThreadSize; // 线程池的最大大小
    @Value("${duijie.maxQueueSize:500}")
    private int maxQueueSize; // 排队队列最大大小

    @Bean
    public ThreadPoolTaskExecutor getExecutorService() {
        // 创建线程池
//            executorService = Executors.newFixedThreadPool(maxThreadSize);
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);
        executor.setMaxPoolSize(maxThreadSize);
        executor.setKeepAliveSeconds(60);
        executor.setQueueCapacity(maxQueueSize);

        return executor;
    }
}